from Goldenberry.optimization.ga.GbSelectorMgr.Selectors import *
from Goldenberry.optimization.ga.GbSelectorMgr.SelectionContext import SelectionContext
from Goldenberry.optimization.ga.DataType.SelectionParams import SelectionParams
from Goldenberry.optimization.ga.GbSelectorMgr.ISelectorMgt import ISelectorMgt
from Goldenberry.optimization.ga.GbSelectorMgr.ISelectorSetup import ISelectorSetup

class Selector(ISelectorMgt, ISelectorSetup):
    """description of class"""
    def __init__(self):
        self.selector_context = SelectionContext()

    #Override methods of ISelectorMgt
    def set_selection(self, selection_method):
        self.selection_method = selection_method
        if selection_method == 'Roulette':
           self.selector_context.set_curr_selection_str(Roulette())
        elif selection_method == 'Tournament':
           self.selector_context.set_curr_selection_str(Tournament())
        else:
           self.selector_context.set_curr_selection_str(Elitist())
           

    def select_parents(self, num_parents, population, costs):
        return self.selector_context.select_parents(num_parents, population, costs)


    #Override methods of ISelectorSetup
    def get_selection_method(self):
        return self.selection_method

    def set_selection_method(self, selection_method):
        self.selection_method = selection_method#SelectionParams(selection_method)
        

